<?php

require_once '../twitter.class.php';

// ENTER HERE YOUR CREDENTIALS (see readme.txt)
$consumerKey 				='MkTymKX3Sof1GroACmKNCw';
$consumerSecret				='rqTZtemtzEdHqGhH479PcBxGYdLkXONidwiGpec5nk';
$accessToken				='351497833-9mTQSXoGn144ATDQIFnkgYECgtxGwSx6epZbBgdE';
$accessTokenSecret 			='Pi0MJcYJkWCYiL3LI0mbwnJPB3JZTlEMTfgRzgfqoo';
$twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
if (!$twitter->authenticate()) {
	die('Invalid name or password');
}
else{
	echo 'OK';
}
//var_dump($twitter);
//$status = $twitter->send(' nice day');
//23967578
//
//try{
//	$follow = @$twitter->getFollowers('23967578','ErinAndrews',"1376437298656726080");
//}
//catch(exception $e){
//echo "xxx";
//	var_dump($e);
//}
//var_dump($follow);
//
//echo count($follow->ids);
//TigerWoods


flush ();
ob_implicit_flush();
set_time_limit(300000);
$follow = $twitter->getFollowers('Vietnamtweet',108205805);


while(1==1)
{
	foreach($follow->ids as $id)
	{
		usleep(2000);	
		try{	
			$res= $twitter->follow($id);
		}
		catch(exception $e){
			$hasError = 1;
			$msg =$e->getMessage();
		}
		if(!$hasError)
			echo "following $id sucessful <br/>";
		else
		{		
			echo "error with $id. Message: $msg <br/>";
			$hasError=null;
		}
		ob_flush ();
		flush ();
		
	}
	$follow = $twitter->getFollowers('Vietnamtweet',$follow->next_cursor_str);
}
var_dump($res);
set_time_limit(60);